from pymysql import Connection
#获取到MySQL数据库的链接对象
#构建到MySQL数据库的链接
conn=Connection(
    host="localhost",#主机名（IP地址也行）
    port=3306,#端口  MySQL数据库端口默认3306
    user='root',#账户
    password='zc050628',#密码
    autocommit=True#设置自动提交  无需conn.commit
)
print(conn.get_server_info())
#执行非查询性质SQL
cursor=conn.cursor()    #获取游标对象
#选择数据库
# conn.select_db('test')
#执行SQL
# cursor.execute('create table test_pymysql(id int);')
#执行查询性质SQL
# conn.select_db('world')
# cursor.execute('select * from student')

# results=cursor.fetchall()
# for r in results:
#     print(r)
#关闭链接
# conn.close()


#执行数据插入语句
conn.select_db('world')
cursor.execute("insert into student values(1111,'初华',16)")
#通过commit确认
conn.commit()
# results=cursor.fetchall()
# for r in results:
#     print(r)
conn.close()